package com.lzx.answer.controller;

import com.lzx.answer.entity.Problem;
import com.lzx.answer.entity.vo.ProblemParams;
import com.lzx.answer.service.ProblemService;
import com.lzx.common.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lzx
 * @since 2022-10-05
 */
@RestController
@RequestMapping("/answer/problem")
public class ProblemController {
    @Resource
    private ProblemService problemService;

    //获取所有问题
    @GetMapping("/getProblemList/{current}/{size}")
    public R getProblemList(@PathVariable int current, @PathVariable int size) {
        return problemService.getProblemList(current, size);
    }

    //新增问题
    @PostMapping("/addProblem")
    public R addProblem(@RequestBody Problem problem) {
        return problemService.addProblem(problem);
    }

    //修改问题
    @PutMapping("/updateProblem")
    public R updateProblem(@RequestBody Problem problem) {
        return problemService.updateProblem(problem);
    }

    //删除问题
    @DeleteMapping("/deleteProblem/{ids}")
    public R deleteProblem(@PathVariable List<Long> ids) {
        return problemService.deleteProblem(ids);
    }

    //根据id获取问题信息
    @GetMapping("/{id}")
    public R getProblem(@PathVariable Long id) {
        return problemService.getProblem(id);
    }

    //搜索
    @PostMapping("/searchProblem")
    public R searchProblem(@RequestBody ProblemParams problemParams) {
        return problemService.searchProblem(problemParams);
    }

    //导出
    @GetMapping("/exportProblem")
    public void exportProblem(HttpServletResponse response) {
        problemService.exportProblem(response);
    }
}
